
import React from 'react';
import { observer, inject } from 'mobx-react';
import { withRouter } from 'react-router-dom';
import { Form, RouteLayout ,ShareAuth } from 'weaver-mobile-page';
import { Modal, ActivityIndicator,Tools } from 'weaver-mobile';
const ButtonGroup = RouteLayout.ButtonGroup;
const alert = Modal.alert;
const getLabel = Tools.getLabel;
@inject('authorityAddStore')
@withRouter
@observer
export default class AuthorityAdd extends React.Component {

    componentDidMount() {
        const store = this.props.authorityAddStore;
        store.initForm(this.props);
    }

    render() {
        const { authorityAddStore, history } = this.props;
        const { form, buttonProps, complete } = authorityAddStore;

        let buttonGroupData = [];
        buttonGroupData.push({
            key: 'clear',
            text: getLabel('201','取消'),
            onClick: () => alert('',getLabel('390915','确定要离开吗?'), [
                { text: getLabel('201','取消'), onPress: () => { } },
                { text: getLabel('83446','确定'), onPress: () => history.go(-1) },
            ])
        });
        buttonGroupData.push({
            key: 'submit',
            text: getLabel('615','提交'),
            onClick: () => this.buttonClick('submit'),
            type: 'primary',
            disabled: buttonProps.disabled,
            loading: buttonProps.loading
        });

        if(complete&&form.isInit){
            return <div className={"crm-form-main"}>
            <div className="crm-form-content">
                <Form store={form} />
            </div>
            <ButtonGroup data={buttonGroupData} />
        </div>;
        }else{
            return <div className={"crm-bg-loading"}>
                <ActivityIndicator text="Loading..." />
            </div>;
        }
    }

    buttonClick = (clickType) => {
        const store = this.props.authorityAddStore;
        store.buttonClick(clickType);
    }



}